package com.doge.walknovel.business.novel.reply

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.wnpro.R
import com.doge.walknovel.api.model.CommentInfo
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.walknovel.core.base.adapters.ITEM_CLICKED
import com.doge.wnpro.databinding.CellNovelReplyBinding
import com.doge.walknovel.utils.*

class ReplyViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellNovelReplyBinding = CellNovelReplyBinding.inflate(LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        binding.collect.setOnClickCallback {
            callback.invoke(ITEM_CLICKED, itemView.tag)
        }
    }

    fun bind(item: CommentInfo) {
        itemView.tag = item
        binding.avatar.load(
            item.profilePicture,
            R.mipmap.comments_avatar_default,
            transformation = CircleCrop,
            width = 36.dp, height = 36.dp,
        )
        binding.nickname.text = item.nickName
        binding.timestamp.text = item.commentTime?.timeDesc
        binding.content.text = item.content
        binding.collectImage.setImageResource(if (item.likeFlag == 1) R.mipmap.comments_collect_light else R.mipmap.comments_collect_normal)
        binding.collectValue.text = (item.likeCount ?: 0).toString()
    }
}